#include "strategy.h"

Strategy::Strategy(Player *player, const Cards &cards)
{
    m_player=player;
    m_cards=cards;
}

Cards Strategy::findSamePointCards(Card::CardPoint point, int count)
{
    if(count<1||count>4)
    {
        return Cards();
    }
    //大小王
    if(point==Card::Card_SJ||point==Card::Card_BJ)
    {
        if(count>1)
        {
            return Cards();
        }
        Card card;
        card.setPoint(point);
        card.setSuti(Card::suit_Begin);
        if(m_cards.contains(card))
        {
            Cards cards;
            cards.add(card);
            return cards;
        }
        return Cards();
    }
    //不是大小王
    int findCount=0;
    Cards findcards;
    for(int suit=Card::suit_Begin;suit<Card::Suit_End;suit++)
    {
        Card card;
        card.setPoint(point);
        card.setSuti((Card::CardSuit)suit);
        if(m_cards.contains(card))
        {
            findCount++;
            findcards.add(card);
            if(findCount==count)
            {
                 return findcards;
            }
        }
    }
    return Cards();
}

QVector<Cards> Strategy::findCardsByCount(int count)
{
    if(count<1||count>4)
    {
        return QVector<Cards>();
    }

    QVector<Cards> cardsArray;
    for(Card::CardPoint point = Card::Card_3; point < Card::Card_End; point = (Card::CardPoint)(point+1))
    {
        if(m_cards.pointCount(point) == count)
        {
            Cards cs;
            cs << findSamePointCards(point, count);
            cardsArray << cs;
        }
    }
    return cardsArray;

}

Cards Strategy::getRangeCards(Card::CardPoint begin, Card::CardPoint end)
{
    Cards rangeCards;
    for(Card::CardPoint point = begin; point < end; point = (Card::CardPoint)(point+1))
    {
        int count = m_cards.pointCount(point);
        Cards cs = findSamePointCards(point, count);
        rangeCards << cs;
    }
    return rangeCards;
}

QVector<Cards> Strategy::findCardType(PlayHand hand, bool beat)
{
    PlayHand::HandType type = hand.type();
    Card::CardPoint point = hand.pt();
    int extra = hand.extra();

    // 确定起始点数
    Card::CardPoint beginPoint = beat ? Card::CardPoint(point + 1) : Card::Card_3;
}


QVector<Cards> Strategy::getCards(Card::CardPoint point, int number)
{
    QVector<Cards> findCardsArray;
    for(Card::CardPoint pt=point; pt < Card::Card_End; pt = (Card::CardPoint)(pt + 1))
    {
        // 目的是尽量不拆分别的牌型
        if(m_cards.pointCount(pt) == number)
        {
            Cards cs = findSamePointCards(pt, number);
            findCardsArray << cs;
        }
    }
    return findCardsArray;
}


